package com.kding.deviceunique

import android.text.TextUtils

/**
 * 扩展方法 获取字符串包含多少个key
 */
fun String.countStr(key: String): Int {
    if (TextUtils.isEmpty(this) || TextUtils.isEmpty(key)) {
        return 0
    }
    var count = 0
    var index = 0
    index = this.indexOf(key, index)
    while (index != -1) {
        count++
        index = this.substring(index + key.length, this.length).indexOf(key, index + 1)
    }
    return count
}